
#include "enemy.h"
#include "config.h"
enemy::enemy()
{
    //资源加载
    m_enemy1.load(ENEMY_PATH1);
    m_enemy2.load(ENEMY_PATH2);
    m_enemy3.load(ENEMY_PATH3);
    m_enemy4.load(BULLET2_PATH);
    m_enemy5.load(BULLET2_PATH);

    m_x=0;
    m_y=0;
    m_x2=0;
    m_y2=0;
    m_x4=0;
    m_y4=0;
    m_x5=0;
    m_y5=0;

    m_free=true;
    m_free2=true;
    m_free3=true;
     m_free4=true;
     m_free5=true;

    m_speed=ENEMY_SPEED;
    m_rect1.setWidth(m_enemy1.width());
    m_rect1.setHeight(m_enemy1.height());
    m_rect1.moveTo(m_x,m_y);
    m_rect2.setWidth(m_enemy2.width());
    m_rect2.setHeight(m_enemy2.height());
    m_rect2.moveTo(m_x2,m_y2);
    m_rect3.setWidth(m_enemy3.width());
    m_rect3.setHeight(m_enemy3.height());
    m_rect3.moveTo(m_x3,m_y3);
    m_rect4.setWidth(m_enemy4.width());
    m_rect4.setHeight(m_enemy4.height());
    m_rect4.moveTo(m_x4,m_y4);
    m_rect5.setWidth(m_enemy5.width());
    m_rect5.setHeight(m_enemy5.height());
    m_rect5.moveTo(m_x5,m_y5);

}

void enemy::updatePosition()
{
    if(m_free)
    {
        return;


    }
    m_y+=m_speed;
    m_rect1.moveTo(m_x,m_y);

    if(m_free2)
    {
        return;


    }
    m_y2+=m_speed;
    m_rect2.moveTo(m_x2,m_y2);

    if(m_free3)
    {
        return;


    }
    m_y3+=m_speed;
    m_rect3.moveTo(m_x3,m_y3);

    if(m_free4)
    {
        return;


    }
    m_y4+=m_speed;
    m_rect4.moveTo(m_x4,m_y4);

    if(m_free5)
    {
        return;


    }
    m_y5+=m_speed;
    m_rect5.moveTo(m_x5,m_y5);



    //超出处理

    if(m_y>=GAME_HEIGHT+m_rect1.height())
    {
        m_free=true;
    }
    if(m_y2>=GAME_HEIGHT+m_rect2.height())
    {
        m_free2=true;
    }
    if(m_y3>=GAME_HEIGHT+m_rect3.height())
    {
        m_free3=true;
    }
    if(m_y4>=GAME_HEIGHT+m_rect4.height())
    {
        m_free4=true;
    }
    if(m_y5>=GAME_HEIGHT+m_rect5.height())
    {
        m_free5=true;
    }

}
